import 'package:flutter/material.dart';
import 'package:star_author/provider/utils/persist.dart';
import 'package:star_author/provider/utils/provider_lib.dart';

class ConfigProvider<T> with ChangeNotifier, ProviderLib, Persist {
  Map<String, dynamic> _config = {
    'waitconfirm_backflow_description':
        '平台打款时间为每天两次：\n前一天17:00之后至当天11:00之前接受回款的回流单在当天12:00打款；\n当天11:00至17:00接收回款的回流单将在当天18:00打款',
    'categories': [
      {
        "id": 1,
        "name": "翡翠",
        "position": 100000,
        "backflow_tips": "B/C货/变种/烧红烧黄/断裂破损/原石等翡翠不支持回流---啦啦啦啦会变测试",
        "created_at": "2020-11-05 19:58:50 +0800",
        "updated_at": "2022-03-09 17:47:04 +0800",
        "image":
            "https://huiliu-staging-resources.huiliu.net/resources/pnlxrx67u38pxgnedhqto4wimf0h?x-oss-process=image%2Fresize%2Cw_300",
        "real_image":
            "https://huiliu-staging-resources.huiliu.net/resources/o38d17binjl63ur2qy1ajina77uh?x-oss-process=image%2Fresize%2Cw_300"
      },
      {
        "id": 2,
        "name": "和田玉",
        "position": 1000,
        "backflow_tips":
            "目前仅支持中高端俄料和籽料回流！ 韩料/低端俄料/墨玉/黑青/罗甸玉/金镶玉/925银镶和田玉等暂时不予回流。",
        "created_at": "2020-11-05 19:58:51 +0800",
        "updated_at": "2022-03-16 16:47:38 +0800",
        "image":
            "https://huiliu-staging-resources.huiliu.net/resources/3xxs43zkjwuwm1s2c91hgkntqhqi?x-oss-process=image%2Fresize%2Cw_300",
        "real_image":
            "https://huiliu-staging-resources.huiliu.net/resources/7h3m29mzheshamhhavhkiqpgi3bu?x-oss-process=image%2Fresize%2Cw_300"
      }
    ],
    'settings': {
      "auditing_version": true, //apple 审核，隐藏微信登陆
      "deduct_guarantee_duration_hours": 24,
      "certificate_map": {
        "gdsj": "广东省检",
        "gdgj": "GDTC国检",
        "other": "其他国内证书",
        "gia": "GIA",
        "grs": "GRS",
        "iother": "其他国际证书"
      },
      "expired_evaluation_duration": 12,
      "categories": ["翡翠", "和田玉", "钻石", "彩宝", "其他"],
      "shipments": [
        {
          "id": 3,
          "price": "0.0",
          "title": "合并发货",
          "description": "货品暂存回流公司，发货时请联系客服补运费",
          "pickup_by_user": false
        },
        {
          "id": 4,
          "price": "0.0",
          "title": "上门取货",
          "description": null,
          "pickup_by_user": true
        },
        {
          "id": 5,
          "price": "0.0",
          "title": "顺丰到付",
          "description": "自行支付运费，以顺丰公司实际收费为准",
          "pickup_by_user": false
        },
        {
          "id": 1,
          "price": "10.0",
          "title": "京东快递",
          "description": null,
          "pickup_by_user": false
        }
      ],
      "rong_cloud_app_key": "y745wfm8y5e2v",
      "app_download_intro_image":
          "https://huiliu-production-resources.huiliu.net//miniprogram/common/app_download_intro.png",
      "backflow_tender_by_guarantee_times": 5,
      "evaluation_text": "竞拍",
      "evaluation_thumb":
          "https://huiliu-production-resources.huiliu.net/miniprogram/evaluation/tender.png",
      "evaluation_default_description_text": "已清洗 不包邮 竞拍货品不支持退货",
      "store_default_description_text": "不议价 不包邮 7天无理由退货",
      "common_default_description_text": "",
      "order_confirm_duration_days": 7,
      "backflow_confirm_duration_hours": 24,
      "rate_for_platform": 0.2,
      "rate_for_tenders": 1.35,
      "rate_for_hitter": 0.05,
      "customer_service_account": "Huiliu303",
      "customer_service_qrcode_url":
          "https://huiliu-production-resources.huiliu.net//miniprogram/common/customer_service_qrcode.jpg",
      "courier_companies": {
        "other": "其他",
        "zhaijisong": "宅急送",
        "shentong": "申通快递",
        "yunda": "韵达快递",
        "debangkuaidi": "德邦快递",
        "jd": "京东物流",
        "yuantong": "圆通快递",
        "tiantian": "天天快递",
        "ems": "EMS",
        "shunfeng": "顺丰快递",
        "zhongtong": "中通快递",
        "huitongkuaidi": "百世快递",
        "youzhengguonei": "邮政快递包裹"
      },
      "backflow_finished_count": 50352,
      "basic_flows": [
        "https://huiliu-production-resources.huiliu.net/resources/vb3l3pnzluulqssscttsj2jf3lp7",
        "https://huiliu-production-resources.huiliu.net/resources/dov7ow4kiuf0l0e21pqmvbu5e3bq",
        "https://huiliu-production-resources.huiliu.net/resources/4denypvgnxa6jktx6bjrb4gybhoo",
        "https://huiliu-production-resources.huiliu.net/resources/8bgtce5nd5daebxnltddymfhm2du",
        "https://huiliu-production-resources.huiliu.net/resources/5topiyddl5mvm3fxnt09h37n7b54"
      ],
      "vocabularies": [],
      "minimum_evaluation_length": 10,
      "top_specialists": [14, 21, 20, 5, 16, 13, 25],
      "customer_service_user": 25,
      "except_user_list": [11],
      "treasure_specialist_ids": [
        17,
        18,
        22,
        19,
        20,
        14,
        15,
        12,
        31,
        24,
        16,
        13,
        30,
        36,
        21,
        25,
        48,
        5,
        165,
        199,
        38,
        378
      ],
      "user_for_clone_backflow": 5,
      "minimum_assessment_length": 0,
      "bshgem_backflow_ids": [
        893,
        878,
        927,
        677,
        380,
        777,
        1223,
        169,
        172,
        183,
        1058,
        1059,
        1286,
        1131
      ],
      "white_list_mchids": [],
      "white_list_user_ids_for_offline_backflows": [410, 5, 162, 378, 19, 1],
      "auditing_mini_programming_version": "",
      "withdraw_limited": 1,
      "low_level_targets": [0, 1, 2],
      "blacklist_tender_ids": [],
      "mobiles_without_code": ["13800138000", "13751852549"],
      "referrer_default_app_url": "https://huiliu.net/download",
      "mini_programming_evaluation_thumb_url":
          "https://huiliu-production-resources.huiliu.net/miniprogram/evaluation/evaluation.png",
      "mini_programming_tender_thumb_url":
          "https://huiliu-production-resources.huiliu.net/miniprogram/evaluation/tender.png",
      "dynamic_switch_of_tender_base_line": true,
      "flaw_default_description_text": "商品描述仅对纹裂等瑕疵做粗略说明 并且图片可能有色差 请到直播间看实物展示",
      "upload_files_url":
          "https://assistant.huiliu.net/admin_api/v1/file_uploads",
      "admin_users_with_highest_priority": [1, 3, 15, 24],
      "minimum_tender_length": 0,
      "earnest_money_list": [100, 500, 1000, 5000, 10000, 50000],
      "watermark_switch": false,
      "need_convert_mov_to_mp4": true,
      "auditing_app_version": "",
      "expired_evaluation_duration_with_count_down": 12,
      "shortest_recording_video_time": 5,
      "deduct_guarantee_rate": 0,
      "questions_type_show": [
        {"question_type": "safety_of_goods", "text": "货品安全"},
        {"question_type": "about_money", "text": "钱款相关"},
        {"question_type": "cost", "text": "费用问题"}
      ],
    }
  };

  ConfigProvider() {
    _config = persistInit(key: 'config', defaultData: _config);
    providerInit(
      _config,
      notify: notifyListeners,
      persistSave: persistSave,
    );
    notifyListeners();
  }

  getPays({bool isBond: false}) {
    List<Map<String, dynamic>> result = [];
    List pay_channel_white_list = [];
    Map<String, dynamic> map = get('settings');
    if (isBond) {
      pay_channel_white_list = map['pay_channel_white_list_guarantee'] ?? [];
    } else {
      pay_channel_white_list = map['pay_channel_white_list'] ?? [];
    }
    pay_channel_white_list.forEach((element) {
      Map<String, dynamic> map = {};
      switch (element) {
        case "alipay":
          map = {
            "title": "支付宝",
            "icon": "shop_car/ali_pay",
            'pay_type': 'alipay'
          };
          break;
        case "wx_lite":
          map = {
            "title": "微信支付",
            "icon": "shop_car/we_chat_pay",
            'pay_type': 'wechat'
          };
          break;
        case "union":
          map = {"title": "云闪付", "icon": "ic_union_pay", 'pay_type': 'union'};
          break;
      }
      result.add(map);
    });
    return result;
  }
}
